package com.sunop.comment.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.sunop.comment.model.Comment;
import com.sunop.comment.model.CommentPageQueryDTO;
import com.sunop.comment.model.CommentReplyPO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @since 2025-03-25
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    Page<Comment> pageQuery(CommentPageQueryDTO commentPageQueryDTO);

    @Select("select uid from comment where id = #{id}")
    int selectCidById(Integer id);

    @Insert("insert into comment_reply (uid, content, to_cid, to_name, author, avatar, role) values (#{uid}, #{content}, #{toCid}, #{toName}, #{author}, #{avatar}, #{role})")
    void insertReply(CommentReplyPO commentReplyPO);

    Page<CommentReplyPO> replyPageQuery(int cid, CommentPageQueryDTO commentPageQueryDTO);

    @Select("select uid from comment_reply where id = #{id}")
    int selectReplyCidById(Integer id);

    @Delete("delete from comment_reply where id = #{id}")
    void deleteReplyById(Integer id);
}
